package string;

import java.io.*;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;

/**
 * Author: hujian
 * Date: 2018/12/15 19:20
 * Description: <描述>
 */
public class ZipEntry {
    public static void main(String[] args) {
        String file = "/opt/fonsview/NE/lcm/template//fcrs/cacheRule//84.zip";
        ZipFile zf = null;
        ZipInputStream zin = null;
        InputStream in = null;
        try {
            zf = new ZipFile(file);
            in = new BufferedInputStream(new FileInputStream(file));
            zin = new ZipInputStream(in);

            String fcrs_cdn_big_xml = getFcrsCacheRuleFile(zf, zin, "cdn_cacherule_big.xml");
            String fcrs_cdn_small_xml = getFcrsCacheRuleFile(zf, zin, "cdn_cacherule_small.xml");
            String fcrs_webcache_big_xml = getFcrsCacheRuleFile(zf, zin, "webcache_cacherule_big.xml");
            String fcrs_webcache_small_xml = getFcrsCacheRuleFile(zf, zin, "webcache_cacherule_small.xml");

            System.out.println("jj");

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
        private static String getFcrsCacheRuleFile(ZipFile zf, ZipInputStream zin, String fileName) throws IOException {
        java.util.zip.ZipEntry ze;
        while ((ze = zin.getNextEntry()) != null) {
            if (ze.isDirectory()) {
                continue;
            } else {
                String file_name = ze.getName();
                if (fileName.equals(file_name)) {
                    return readFileFromZip(zf, ze);
                }
            }
        }
        return "";
    }
    private static String readFileFromZip(ZipFile zf, java.util.zip.ZipEntry ze) throws IOException {
        StringBuilder sb = new StringBuilder();
        BufferedReader buff = null;
        buff = new BufferedReader(new InputStreamReader(zf.getInputStream(ze)));
        String str;
        while ((str = buff.readLine()) != null) {
            sb.append(str).append("\n");
        }
        buff.close();
        return sb.toString();
    }
}
